package com.hyy.book2.controller;


import com.hyy.book2.model.BookInfo;
import com.hyy.book2.model.PageRequest;
import com.hyy.book2.model.PageResponse;
import com.hyy.book2.model.Result;
import com.hyy.book2.service.BookService;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequestMapping("/book")
@RestController
public class BookController {

    @Autowired
    private BookService bookService;

    @RequestMapping("/addBook")
    public String addBook(BookInfo bookInfo) {
        log.info("开始参数校验");
        if(bookInfo==null||
                !StringUtils.hasLength(bookInfo.getBookName())
                || !StringUtils.hasLength(bookInfo.getAuthor())
                || (bookInfo.getCount() == null)
                || (bookInfo.getPrice() == null)
                || !StringUtils.hasLength(bookInfo.getPublish())){
            return "参数不合法，请重新检查！";
        }
        return bookService.InsertBook(bookInfo);
    }

    @RequestMapping("/getListByPage")
    public Result<PageResponse<BookInfo>> getListByPage(PageRequest pageRequest, HttpSession session) {

        //强制登陆
        if(session==null
        ||session.getAttribute(Constants.SESSION_USER_YEY)==null
        ||!StringUtils.hasLength((String)session.getAttribute(Constants.SESSION_USER_YEY)))


            if(pageRequest==null
                    ||pageRequest.getCurPage()==null
            ||pageRequest.getPageSize()==null){
                return Result.invalidParameter();
            }


    }
}
